-- run_lua.proto
-- Run lua in other servers.
-- Only used between game servers.

local M = {}

local log = require("log"):new("svc_run_lua")
local pb = require("protobuf")

log:debug("loading service...")

-- Todo: Base服要禁止Clt请求

function M.Run(ctx, content)
	local req = pb.decode("svr.RunLuaRequest", content)
	log:debug("Run: "..req.codes)  -- todo: from where?
	local result = assert(load(req.codes))()
	local res_type = type(result)
	local codes = ""
	if ("boolean" == res_type or
		"string" == res_type or
		"number" == res_type) then
		codes = ""..result
	end
	local resp = { codes = codes }
	local resp_str = pb.encode("svr.RunLuaResponse", resp)
	c_rpc.reply_to(ctx, resp_str)
end  -- Run()

require("rpc_request_handler").register_service("svr.RunLua", M)
return M 
